DACSS 601: Data Science Fundamentals - FALL 2022
  • Fall 2022 Posts
  • Contributors
  • DACSS

Challenge 5

  • Course information
    • Overview
    • Instructional Team
    • Course Schedule
  • Weekly materials
    • Fall 2022 posts
    • final posts

On this page

  • Challenge Overview
  • Read in data
    • Briefly describe the data
  • Tidy Data
  • Univariate Visualizations

Challenge 5

challenge_5
railroads
cereal
air_bnb
pathogen_cost
australian_marriage
public_schools
usa_households
Introduction to Visualization
Author

Lai Wei

Published

November 14, 2022

library(tidyverse)
library(ggplot2)
library(dplyr)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Challenge Overview

Today’s challenge is to:

  1. read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
  2. tidy data (as needed, including sanity checks)
  3. mutate variables as needed (including sanity checks)
  4. create at least two univariate visualizations
  • try to make them “publication” ready
  • Explain why you choose the specific graph type
  1. Create at least one bivariate visualization
  • try to make them “publication” ready
  • Explain why you choose the specific graph type

R Graph Gallery is a good starting point for thinking about what information is conveyed in standard graph types, and includes example R code.

(be sure to only include the category tags for the data you use!)

Read in data

Read in one (or more) of the following datasets, using the correct R package and command.

  • AB_NYC_2019.csv ⭐⭐⭐
NYC <- read_csv("_data/AB_NYC_2019.csv") 
NYC
# A tibble: 48,895 × 16
      id name      host_id host_…¹ neigh…² neigh…³ latit…⁴ longi…⁵ room_…⁶ price
   <dbl> <chr>       <dbl> <chr>   <chr>   <chr>     <dbl>   <dbl> <chr>   <dbl>
 1  2539 Clean & …    2787 John    Brookl… Kensin…    40.6   -74.0 Privat…   149
 2  2595 Skylit M…    2845 Jennif… Manhat… Midtown    40.8   -74.0 Entire…   225
 3  3647 THE VILL…    4632 Elisab… Manhat… Harlem     40.8   -73.9 Privat…   150
 4  3831 Cozy Ent…    4869 LisaRo… Brookl… Clinto…    40.7   -74.0 Entire…    89
 5  5022 Entire A…    7192 Laura   Manhat… East H…    40.8   -73.9 Entire…    80
 6  5099 Large Co…    7322 Chris   Manhat… Murray…    40.7   -74.0 Entire…   200
 7  5121 BlissArt…    7356 Garon   Brookl… Bedfor…    40.7   -74.0 Privat…    60
 8  5178 Large Fu…    8967 Shunic… Manhat… Hell's…    40.8   -74.0 Privat…    79
 9  5203 Cozy Cle…    7490 MaryEl… Manhat… Upper …    40.8   -74.0 Privat…    79
10  5238 Cute & C…    7549 Ben     Manhat… Chinat…    40.7   -74.0 Entire…   150
# … with 48,885 more rows, 6 more variables: minimum_nights <dbl>,
#   number_of_reviews <dbl>, last_review <date>, reviews_per_month <dbl>,
#   calculated_host_listings_count <dbl>, availability_365 <dbl>, and
#   abbreviated variable names ¹​host_name, ²​neighbourhood_group,
#   ³​neighbourhood, ⁴​latitude, ⁵​longitude, ⁶​room_type

Briefly describe the data

Tidy Data

Using colnames() to check columns’ names. And there are 15 columns’ names in total.And by dim(), getting the dimensions of NYC, there are 261 rows and 16 columns

colnames(NYC)
 [1] "id"                             "name"                          
 [3] "host_id"                        "host_name"                     
 [5] "neighbourhood_group"            "neighbourhood"                 
 [7] "latitude"                       "longitude"                     
 [9] "room_type"                      "price"                         
[11] "minimum_nights"                 "number_of_reviews"             
[13] "last_review"                    "reviews_per_month"             
[15] "calculated_host_listings_count" "availability_365"              
dim(NYC)
[1] 48895    16

We can directly refer to the column, neighbourhood_group by select(). Then we can make a table of neighbourhood_group for easily reading. And proportional table can return the value of occurrence of each value.

select(NYC,neighbourhood_group) %>% table() %>% prop.table() 
neighbourhood_group
        Bronx      Brooklyn     Manhattan        Queens Staten Island 
  0.022313120   0.411166786   0.443010533   0.115880969   0.007628592 

Univariate Visualizations

NYC_Room <- NYC %>% filter(neighbourhood_group == "Bronx") %>%  
  select(host_name,price,room_type) %>% group_by(room_type) %>% 
  summarise(count=n())
NYC_Room
# A tibble: 3 × 2
  room_type       count
  <chr>           <int>
1 Entire home/apt   379
2 Private room      652
3 Shared room        60

From it, we can get the summary of room type in Bronx area, and use ggplot o to show in bar graph.

ggplot(NYC_Room, aes(x = room_type)) + geom_bar(color = "red")

Source Code
---
title: "Challenge 5"
author: "Lai Wei"
description: "Introduction to Visualization"
date: "11/14/2022"
format:
  html:
    toc: true
    code-copy: true
    code-tools: true
categories:
  - challenge_5
  - railroads
  - cereal
  - air_bnb
  - pathogen_cost
  - australian_marriage
  - public_schools
  - usa_households
---

```{r}
#| label: setup
#| warning: false
#| message: false

library(tidyverse)
library(ggplot2)
library(dplyr)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```

## Challenge Overview

Today's challenge is to:

1)  read in a data set, and describe the data set using both words and any supporting information (e.g., tables, etc)
2)  tidy data (as needed, including sanity checks)
3)  mutate variables as needed (including sanity checks)
4)  create at least two univariate visualizations
   - try to make them "publication" ready
   - Explain why you choose the specific graph type
5)  Create at least one bivariate visualization
   - try to make them "publication" ready
   - Explain why you choose the specific graph type

[R Graph Gallery](https://r-graph-gallery.com/) is a good starting point for thinking about what information is conveyed in standard graph types, and includes example R code.

(be sure to only include the category tags for the data you use!)

## Read in data

Read in one (or more) of the following datasets, using the correct R package and command.

-   AB_NYC_2019.csv ⭐⭐⭐


```{r}
NYC <- read_csv("_data/AB_NYC_2019.csv") 
NYC
```

### Briefly describe the data

## Tidy Data 

Using colnames() to check columns' names. And there are 15 columns' names in total.And by dim(), getting the dimensions of NYC, there are 261 rows and 16 columns 

```{r}
colnames(NYC)
dim(NYC)
```
We can directly refer to the column, neighbourhood_group by select(). Then we can make a table of neighbourhood_group for easily reading. And proportional table can return the value of occurrence of each value. 

```{r}
select(NYC,neighbourhood_group) %>% table() %>% prop.table() 
``` 

## Univariate Visualizations
```{r}
NYC_Room <- NYC %>% filter(neighbourhood_group == "Bronx") %>%  
  select(host_name,price,room_type) %>% group_by(room_type) %>% 
  summarise(count=n())
NYC_Room
```
From it, we can get the summary of room type in Bronx area, and use ggplot o to show in bar graph. 

```{r}
ggplot(NYC_Room, aes(x = room_type)) + geom_bar(color = "red")
```